package com.xunyin.modules.mtjoin.rest;

import com.xunyin.constant.Constants;
import com.xunyin.modules.mtjoin.domain.MtJoin;
import com.xunyin.modules.mtjoin.service.MtJoinService;
import com.xunyin.pagination.PaginationRequest;
import com.xunyin.pagination.PaginationResponse;
import com.xunyin.utils.StringUtil;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 招商加盟管理controller
 * <p>
 * Created by xunyin
 * CopyRight 讯音云商 https://www.tonetn.com
 */
@AllArgsConstructor
@Api(tags = "共享空间:招商加盟管理")
@RestController
@RequestMapping("api/mtjoin")
public class BackendMtJoinController {

    private final MtJoinService mtJoinService;

    /**
     * 余额明细列表查询
     *
     * @param request HttpServletRequest对象
     * @return 余额明细列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    public ResponseEntity<Map<String, Object>> list(HttpServletRequest request) {
        Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
        Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
        String tel = request.getParameter("tel") == null ? "" : request.getParameter("tel");
        Map<String, Object> searchParams = new HashMap<>();
        if (StringUtil.isNotEmpty(tel)) {
            searchParams.put("tel", tel);
        }
        PaginationRequest paginationRequest = new PaginationRequest();
        paginationRequest.setCurrentPage(page);
        paginationRequest.setPageSize(pageSize);
        paginationRequest.setSearchParams(searchParams);
        PaginationResponse<MtJoin> paginationResponse = mtJoinService.queryListByPagination(paginationRequest);
        Map<String, Object> result = new HashMap<>();
        result.put("paginationResponse", paginationResponse);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
}
